home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / DISK.DOC < prev    next >
Text File  |  1996-02-24  |  26KB  |  957 lines

  1.  
  2. ***************************** DISK & FILE *******************************
  3.  
  4. ASM32 disk & file subroutines Copyright (C) 1993 - 1995 Douglas Herr
  5. All rights reserved
  6.  
  7. The DOS file attribute byte tells you whether a file is read-only,
  8. system, a subdirectory, or may provide other information.  File attribute
  9. bits may be combined.  Each bit of the file attribute means:
  10.  
  11.         0 = normal files
  12.         1 = read-only
  13.         2 = hidden files
  14.         4 = system files
  15.         8 = volume label (only one per disk)
  16.        16 = subdirectories
  17.        32 = archive bit set
  18.  
  19.    Thus a file with an attribute of 18 is a hidden subdirectory (16 OR 2)
  20.  
  21.  
  22.  
  23.                       ASM32 buffered file I/O system
  24.  
  25.     Several ASM32 subroutines are available for buffered file Input or
  26.     Output.  Files to be managed by the buffered I/O system must be opened
  27.     by FOPEN or FCREATE, and must be closed by FCLOSE.  Buffered file I/O
  28.     will be much faster than unbuffered.  ASM32's default buffer size is
  29.     4096 bytes; this can be changed by altering FBUFFER_SIZE in FOPEN.ASM
  30.     and re-assembling.  Up to 20 files can be managed by FOPEN; this can
  31.     be changed by altering NUMBER_OF_FILES in $handle.asm and reassembling.
  32.     ASM32's file I/O subroutines assume DS:@data.
  33.  
  34.     Subroutines: FOPEN        open file & initialize buffer
  35.                  FCREATE      create file & initialize buffer
  36.                  FCLOSE       flush & close output buffer; close file
  37.                  FSEEK        move file pointer & update buffer
  38.                  FGETSTR      read a string from buffer
  39.                  FGETCHR      read a character from buffer
  40.                  FGET         read specified number of bytes from buffer
  41.                  FPUTSTR      write string to buffer
  42.                  FPUTCRLF     write CR+LF to buffer
  43.                  FPUTCHR      write character to buffer
  44.                  FPUT         write specified number of bytes to buffer
  45.  
  46.  
  47. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  48.  
  49. DISKSIZE:    determines total and free disk space
  50. Source:      disksize.asm
  51.  
  52. Call with:   DL = drive number (drive A: = 0, default drive = -1)
  53. Returns:     if CF = 0, EAX = total disk space
  54.                         EDX = free disk space
  55.              if CF = 1, AX = DOS error code
  56.               DiskSize does not trap "drive not ready" errors
  57. Uses:        EAX, EDX, flags
  58. Supports:    all DOS drives
  59. Example:
  60.  
  61. public  example_code
  62. extrn    disksize:near
  63.  
  64. include codeseg.inc
  65.  
  66. ; code
  67. example_code    proc near
  68.         mov    dl,0
  69.         call    disksize
  70.         jc      disk_error
  71.  
  72.  
  73. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  74.  
  75. diskwp:      determines if a floppy disk is write-protected
  76. Source:      diskwp.asm
  77.  
  78. Call with:   DL = floppy disk number (drive A: = 0)
  79. Returns:     AL = BIOS error code
  80.                 0 = no error
  81.                 1 = invalid disk number
  82.                 3 = disk is write-protected or wrong media
  83.               128 = drive not ready
  84. Uses:        EAX, flags
  85. Supports:    physical drives A: and B:
  86. Example:
  87.  
  88. public  check_disk
  89. extrn   diskwp:near
  90.  
  91. include codeseg.inc
  92.  
  93. ; code
  94. check_disk      proc near
  95.         .
  96.         .
  97.         .
  98.         mov     dl,1              ; drive B:
  99.         call    diskwp            ; can I write to this disk?
  100.         jnc     short no_problem
  101.  
  102.  
  103. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  104.  
  105. DOTBAK:      changes the file extension of an existing file to .BAK
  106. Source:      dotbak.asm (strrchr.asm)
  107.  
  108. Call with:   ESI = address of a valid ASCIIZ filename
  109.              dotbak deletes a previous .BAK file of this name and
  110.              renames the input filename.ext to filename.bak.
  111. Returns:     if CF = 0, no error
  112.              if CF = 1, AL = DOS error code.  If AL = 5, the previous
  113.              .BAK filename is probably read-only.  All other errors refer
  114.              to the name change operation.
  115. Uses:        AX, flags
  116. Example:
  117.  
  118. extrn   dotbak:near
  119.  
  120. include dataseg.inc
  121.  
  122. ; data
  123.  
  124. disk_doc  db 'DISK.DOC',0
  125.  
  126. @curseg    ends
  127.  
  128. include codeseg.inc
  129.  
  130. ; code
  131.              .
  132.              .
  133.              .
  134.              mov   esi,offset disk_doc
  135.              call  dotbak
  136.  
  137.  
  138. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  139.  
  140. FCLOSE:      close a file managed by ASM32's buffered file I/O system
  141. Source:      fopen.asm ($handle.asm)
  142.  
  143. Call with:   BX = file handle
  144.              The file must have been opened by FOPEN or FCREATE;  If the
  145.              file is not read-only, the output buffer will be written to
  146.              the disk file before closing the file.
  147. Returns:     if CF = 0, no error
  148.              if CF = 1, AX = error code
  149. Uses:        AX, flags
  150. Example:     see FOPEN
  151.  
  152.  
  153.  
  154.  
  155. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  156.  
  157. FCOPY:       copy a file
  158. Source:      fcopy.asm
  159.  
  160. Call with:   ESI = address of source filename
  161.              EDI = address of destination filename
  162.              Both filenames must be ASCIIZ strings.  Drive and path need
  163.              not be fully specified; filenames may not include * or ?
  164.              wildcards.
  165. Returns:     if CF = 0, no problem
  166.              if CF = 1, AX = DOS error code
  167. Uses:        EAX, CF
  168. Example:
  169.  
  170. extrn   fcopy:near
  171.  
  172. include dataseg.inc
  173.  
  174. ; data
  175.         db 'b:'
  176. source  db 'asm32cw.lib',0         ; copy the library to b:
  177.  
  178. @curseg    ends
  179.  
  180. include codeseg.inc
  181.  
  182. ; code
  183.         .
  184.         .
  185.         lea     esi,source
  186.         mov     edi,esi               ; EDI also points to source
  187.         sub     edi,2                 ; back the pointer to the 'B:'
  188.         call    fcopy
  189.         jc      oops
  190.  
  191.  
  192.  
  193. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  194.  
  195. FCOUNT:      counts the number of files matching an ASCIIZ filespec string.
  196.              The filespec string may include the '*' and '?' wildcards.
  197. Source:      fcount.asm
  198.  
  199. Call with:   EDX pointing to filespec string
  200.              CX = file attributes
  201. Returns:     EAX = number of files matching the filespec string
  202. Uses:        EAX
  203. Example:
  204.  
  205. extrn   fcount:near
  206.  
  207. include dataseg.inc
  208.  
  209. ; data
  210. filespec  db '*.asm',0
  211.  
  212. @curseg    ends
  213.  
  214. include codeseg.inc
  215.  
  216. ; code
  217.         .
  218.         .
  219.         .
  220.         lea    edx,filespec     ; address of filespec string
  221.         xor    cx,cx            ; normal files only
  222.         call   fcount
  223.  
  224.  
  225. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  226.  
  227. FCREATE:     create new file and initialize output buffer
  228. Source:      fcreate.asm ($handle.asm)
  229.  
  230. Call with:   EDX pointing to ASCIIZ filename
  231.              The file is created with write-only access.  If a file with
  232.              the same name already exists, it is truncated to zero
  233.              length by FCREATE.
  234. Returns:     if CF = 0, AX = file handle
  235.              if CF = 1, AX = error code
  236. Uses:        AX, flags
  237. Example:
  238.  
  239. public   myprog
  240. extrn    fcreate:near
  241.  
  242. include  dataseg.inc
  243.  
  244. ; data
  245. file_name   db 'ANYNEW.FIL',0
  246. file_handle dw 0
  247.  
  248. @curseg    ends
  249.  
  250. include codeseg.inc
  251.  
  252. ; code
  253. myprog   proc  near
  254.          .
  255.          .
  256.          .
  257.          lea   edx,file_name
  258.          call  fcreate
  259.          jc    something_went_wrong      ; go to error control code
  260.          mov   file_handle,ax            ; save the handle
  261.          .
  262.          .
  263.          .
  264.  
  265.  
  266. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  267.  
  268. FEXIST:      determines if a file exists and can be opened with read access
  269. Source:      fexist.asm
  270.  
  271. Call with:   EDX pointing to ASCIIZ filename
  272. Returns:     if CF = 0, file exists
  273.              if CF = 1, AX = DOS error code
  274. Uses:        AX, CF; all other flags and registers are saved
  275. Example:
  276.  
  277. extrn    fexist:near
  278.  
  279. include  dataseg.inc
  280.  
  281. ; data
  282. filename db 'asm32.doc',0
  283.  
  284. @curseg    ends
  285.  
  286. include  codeseg.inc
  287.  
  288. ; code
  289.          .
  290.          .
  291.          .
  292.          lea   edx,filename
  293.          call  fexist
  294.          jnc   got_the_file      ; if CF = 0, go on
  295.          jmp   doserror          ; else go to error handling code
  296.  
  297.  
  298.  
  299. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  300.  
  301. FFLUSH:      flushes the ASM32 and DOS output buffers for specified handle
  302. Source:      fflush.asm (fseek.asm)
  303.  
  304. Call with:   BX = file handle
  305.              flushing the buffers guards against data loss in case of system
  306.              failure, such as power loss
  307. Returns:     if CF = 0, no error; function successful
  308.              if CF = 1, AX = DOS error code
  309. Uses:        AX, flags
  310. Example:
  311.  
  312. include codeseg.inc
  313.  
  314. extrn   fflush:near
  315.  
  316. ; code
  317. ; program opens file & writes to file
  318.       .
  319.       .
  320.       .
  321. ; flush the buffers to disk
  322.       mov    bx,handle
  323.       call   fflush
  324.  
  325.  
  326.  
  327. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  328.  
  329. FGET:        read specified number of bytes from file buffer
  330. Source:      fget.asm ($handle.asm, $fget.asm)
  331.  
  332. Call with:   BX = file handle
  333.              ECX = number of bytes requested (up to 4096 bytes)
  334. Returns:     if CF = 0, EAX = number of bytes read
  335.                         EBX points to data in near buffer
  336.              if CF = 1, AX = DOS error code
  337. Uses:        EAX, EBX, flags
  338. Example:
  339.  
  340. extrn   fopen:near, fget:near
  341.  
  342. include dataseg.inc
  343.  
  344. ; data
  345. file_name   db 'asm32.doc',0
  346. file_handle dw 0
  347.  
  348. @curseg    ends
  349.  
  350. include codeseg.inc
  351.  
  352. ; code
  353.           .
  354.           .
  355.           .
  356.           lea   edx,file_name
  357.           call  fopen
  358.           jc    fopen_problem
  359.           mov   file_handle,ax  ; save for later
  360.  
  361.           mov   bx,ax           ; file handle
  362.           mov   ecx,8           ; I want 8 bytes
  363.           call  fget            ;  returned at [EBX]
  364.           jc    read_problem    ; uh oh, trouble ...
  365.           cmp   eax,ecx         ; did I get what I wanted?
  366.           jne   not_enough
  367.           .
  368.           .
  369.  
  370.  
  371.  
  372.  
  373. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  374.  
  375. FGETCHR:     read a character from a file buffer
  376. Source:      fgetchr.asm ($handle.asm)
  377.  
  378. Call with:   BX = file handle
  379. Returns:     if CF = 0, AL = next character from file buffer
  380.              if CF = 1, AX = DOS error code
  381.                         AX = 0 if at end of file
  382. Uses:        AX, flags
  383. Example:
  384.  
  385. extrn   fopen:near, fgetchr:near
  386.  
  387. include dataseg.inc
  388.  
  389. ; data
  390. file_name   db 'asm32.doc',0
  391. file_handle dw 0
  392.  
  393. @curseg    ends
  394.  
  395. include codeseg.inc
  396.  
  397. ; code
  398.           .
  399.           .
  400.           .
  401.           lea   edx,file_name
  402.           call  fopen
  403.           jc    fopen_problem
  404.           mov   file_handle,ax  ; save for later
  405.  
  406.           mov   bx,ax           ; file handle
  407.           call  fgetchr         ; character in AL
  408.           jc    read_problem
  409.  
  410.           .
  411.           .
  412.  
  413.  
  414.  
  415. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  416.  
  417. FGETSTR:     read an ASCII string from a file buffer
  418. Source:      fgetstr.asm ($handle.asm, $fget.asm)
  419.  
  420. Call with:   BX = file handle
  421.              ASCII strings may be terminated with either 0Dh or 0Dh+0Ah.
  422.              After reading each string, FGetStr positions the buffer pointer
  423.              to read the next string.  String length should be less than
  424.              the buffer size.  See FOPEN.
  425.              NOTE THAT THE STRING IN THE BUFFER IS NOT ZERO-TERMINATED.
  426. Returns:     if CF = 0, EBX points to string in buffer
  427.                         ECX = length of ASCII string
  428.                      if ECX = byte length of buffer, string >= size of buffer
  429.                               (default buffer length = 4096 bytes)
  430.              if CF = 1, AX = DOS error code
  431.                         AX = 0 if end of file
  432. Uses:        EBX, EAX, ECX, flags
  433. Example:
  434.  
  435. extrn   fopen:near, fgetstr:near
  436.  
  437. include dataseg.inc
  438.  
  439. ; data
  440. file_name   db 'asm32.doc',0
  441. file_handle dw 0
  442.  
  443. @curseg    ends
  444.  
  445. include codeseg.inc
  446.  
  447. ; code
  448.         .
  449.         .
  450.         .
  451.         lea   edx,file_name
  452.         call  fopen
  453.         mov   al,0            ; read-only access
  454.         jc    fopen_problem
  455.         mov   file_handle,ax  ; save for later
  456.  
  457.         mov   bx,ax           ; file handle
  458.         call  fgetstr
  459.         jc    read_problem
  460.         push  es
  461.         pop   ds              ; string at ES:[EBX]
  462.         call  strndup         ; make a copy for later
  463.         .
  464.         .
  465.         .
  466.  
  467.  
  468.  
  469. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  470.  
  471. filelist:    creates a list of file names matching a filespec mask
  472. Source:      filelist.asm (fcount.asm)
  473.  
  474. Call with:   ESI pointing to filespec mask
  475.              CX = file attribute mask
  476. Returns:     if CF = 0:
  477.                EDI = address of list buffer
  478.                EAX = number of filenames in list
  479.                ECX = list field width
  480.              if CF = 1, AX = DOS error code
  481.              You should use ASM32's HFREE to release the file list
  482.              buffer when you're done with it.
  483. Uses:        EAX, ECX, EDI, flags
  484. Example:
  485.  
  486. public  myproc
  487. extrn   filelist:near
  488.  
  489. include dataseg.inc
  490.  
  491. ; data
  492. filespec db '*.*',0
  493.  
  494. @curseg    ends
  495.  
  496. include codeseg.inc
  497.  
  498. ; code
  499.         .
  500.         .
  501.         .
  502.         lea    esi,filespec
  503.         mov    cx,16            ; normal files and subdirectories
  504.         call   filelist
  505.         jc     cant_do_it       ; oops
  506.  
  507.  
  508.  
  509. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  510.  
  511. FOPEN:       opens existing file and initializes ASM32 buffered I/O
  512. Source:      fopen.asm ($handle.asm)
  513.  
  514. Call with:   EDX pointing to name of file to be opened
  515.              AL = access mode
  516.               0 = read-only access
  517.               1 = write-only access
  518.               2 = read-write access NOT SUPPORTED YET
  519. Returns:     if CF = 0, AX = file handle
  520.              if CF = 1, AX = ASM32 or DOS error code; file not opened
  521.                 if AX = 0, insufficient memory available
  522.                 if AX = 0FFFFh, no handles available in ASM32 I/O array;
  523.                    change NUMBER_OF_HANDLES in $handle.asm and re-assemble
  524.                    (default = 20 handles)
  525. Uses:        AX, flags
  526. Example:
  527.  
  528. public   myprog
  529. extrn    fopen:near, fclose:near
  530.  
  531. include  dataseg.inc
  532.  
  533. ; data
  534. file_name   db 'ASM32.DOC',0
  535. file_handle dw 0
  536.  
  537. @curseg    ends
  538.  
  539. include  codeseg.inc
  540.  
  541. ; code
  542. myprog   proc  near
  543.          .
  544.          .
  545.          .
  546.          lea   edx,file_name
  547.          xor   al,al          ; read-only access
  548.          call  fopen
  549.          jc    something_went_wrong
  550.          mov   file_handle,ax ; save the handle
  551.          .
  552.          .
  553.          .
  554.  
  555. ; all done with this file
  556.          mov   bx,file_handle
  557.          call  fclose
  558.  
  559.  
  560.  
  561. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  562.  
  563. FPUT:        write specified number of bytes to output file buffer
  564. Source:      fput.asm ($handle.asm)
  565.  
  566. Call with:   BX = file handle
  567.              ES:[EDI] pointing to data to write
  568.              ECX = number of bytes to write
  569. Returns:     if CF = 0, no error
  570.              if CF = 1, AX = error code
  571. Uses:        EAX, flags
  572. Example:
  573.  
  574. public  myproc
  575. extrn   fput:near
  576. extrn   fputchr:near
  577. extrn   fputcrlf:near
  578.  
  579. include dataseg.inc
  580.  
  581. ; data
  582. data1    db 'several bytes may be written at once'
  583. data_len equ $-data1
  584.  
  585. @curseg    ends
  586.  
  587. include codeseg.inc
  588.  
  589. ; code
  590.          .
  591.          .
  592.          .
  593.         mov    bx,output_handle
  594.         push   ds
  595.         pop    es
  596.         lea    edi,data1              ; EDI -> data1
  597.         mov    ecx,data_len           ; bytes to write
  598.         call   fput
  599.         call   fputcrlf               ; write CR+LF for new line
  600.                                       ; in ASCII text file
  601.         mov    al,26                  ; End-of-File byte (optional)
  602.         call   fputchr
  603.  
  604.  
  605. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  606.  
  607. FPUTCHR:     write one character to output file buffer
  608. Source:      fputchr.asm (fput.asm)
  609.  
  610. Call with:   BX = output file handle
  611.              AL = character to write
  612. Returns:     if CF = 1, AX = DOS error code
  613.              if CF = 0, no error
  614. Uses:        AX, flags
  615. Example:     see FPUT
  616.  
  617. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  618.  
  619. FPUTCRLF:    write CR+LF pair to output file buffer
  620. Source:      fputcrlf.asm (fput.asm)
  621.  
  622. Call with:   BX = output file handle; file must have been opened by
  623.              FOPEN or FCREATE
  624. Returns:     if CF = 0, no error
  625.              if CF = 1, AX = DOS error code
  626. Uses:        AX, flags
  627. Example:     see FPUT
  628.  
  629.  
  630.  
  631. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  632.  
  633. FPUTSTR:     write an ASCIIZ string to output buffer
  634. Source:      fputstr.asm (strlen.asm, fput.asm)
  635.  
  636. Call with:   BX = file handle
  637.              ES:[EDI] pointing to ASCIIZ string
  638. Returns:     if CF = 0, EAX = bytes written
  639.              if CF = 1, AX = DOS error code
  640. Uses:        EAX, flags
  641. Example:
  642.  
  643. public  myproc
  644. extrn   fputstr:near
  645. extrn   fputcrlf:near
  646.  
  647. include dataseg.inc
  648.  
  649. ; data
  650. strptr   dd 0                         ; pointer to string, assigned by program
  651.  
  652. @curseg    ends
  653.  
  654. include codeseg.inc
  655.  
  656. ; code
  657.          .
  658.          .
  659.          .
  660.         mov    bx,output_handle
  661.         push   ds
  662.         pop    es
  663.         mov    edi,strptr             ; ES:[EDI] -> string
  664.         call   fputstr
  665.         call   fputcrlf               ; write CR+LF for new line
  666.                                       ; in ASCII text file
  667.  
  668.  
  669.  
  670. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  671.  
  672. FSEEK:       move file pointer for a file opened by FOPEN
  673. Source:      fseek.asm ($handle.asm)
  674.  
  675. Call with:   BX = file handle
  676.              AL = method code: 0 = absolute offset from start of file
  677.                                1 = signed offset from current file pointer
  678.                                2 = signed offset from end of file
  679.              EDX = dword offset
  680. Returns:     if CF = 1, AX = DOS error code
  681.              if CF = 0, EAX = new location of file pointer
  682. Uses:        EAX, flags
  683.  
  684. Example:
  685.  
  686. public  whoknows
  687. extrn fopen:near, fseek:near
  688.  
  689. include dataseg.inc
  690.  
  691. ; data
  692. file0   db 'file0.dat',0
  693.  
  694. @curseg    ends
  695.  
  696. include codeseg.inc
  697.  
  698. ; code
  699. whoknows  proc near
  700.         .
  701.         .
  702.         .
  703.         mov     edx,offset file0
  704.         mov     al,1              ; write only
  705.         call    fopen
  706.         jc      error
  707.         xor     edx,edx           ; zero offset
  708.         mov     al,2              ; relative to end of file
  709.         call    fseek             ; move pointer to end of file
  710.  
  711.  
  712.  
  713.  
  714.  
  715. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  716.  
  717. FSIZE:       determines a file's size
  718. Source:      fsize.asm
  719.  
  720. Call with:   BX = valid file handle
  721. Returns:     if CF = 0, EAX = file size
  722.              if CF = 1, AX = DOS error code
  723. Uses:        EAX, CF
  724. Example:
  725.  
  726.  
  727. extrn   fsize:near
  728.  
  729. include dataseg.inc
  730.  
  731. ; data
  732.  
  733. filenam db 'ASM32.DOC',0      ; ASCIIZ filename
  734.  
  735. @curseg    ends
  736.  
  737. include codeseg.inc
  738.  
  739. ; code
  740.         .
  741.         .
  742.         .
  743.         lea     edx,filenam    ; point to filename
  744.         mov     al,0           ;  read-only access (not required by FSIZE)
  745.         call    fopen          ;  open the file
  746.         jc      oops           ; jump to error control
  747.                                ;  else no problem - continue
  748.         mov     bx,ax          ; file handle in BX
  749.         call    fsize          ; returns file size in EAX
  750.  
  751.  
  752. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  753.  
  754. FSTRISTR:    search disk file for text string, case-sensetive
  755. Source:      fstristr.asm (mload.asm, strnlwr.asm, $strstr.asm)
  756.  
  757. FSTRSTR:     search disk file for text string, case-insensetive
  758. Source:      fstrstr.asm (mload.asm, $strstr.asm)
  759.  
  760. Call with:   DS:[EDX] pointing to valid filename
  761.              DS:[ESI] pointing to ASCIIZ string
  762.              EAX = starting offset in file
  763. Returns:     if CF = 1, string not found
  764.              if CF = 0, EAX = offset of start of string in file
  765. Uses:        EAX, flags
  766. Example:
  767.  
  768. include model.inc
  769.  
  770. extrn   fstrstr:near
  771.  
  772. include dataseg.inc
  773.  
  774. text_str  db 'ASM32',0
  775. filename  db 'ASM32.DOC',0
  776.  
  777. @curseg ends
  778.  
  779. include codeseg.inc
  780.         .
  781.         .
  782.         .
  783.         lea    edx,filename
  784.         lea    esi,text_str
  785.         xor    eax,eax            ; start search at beginning of file
  786.         call   fstrstr            ; do case-sensetive search
  787.         jc     short no_good      ; didn't find it
  788.         .
  789.         .
  790.         .
  791.  
  792. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  793.  
  794. GREP:        search specified file(s) for text string
  795. Source:      grep.asm ($mflist.asm)
  796.  
  797. Call with:   DS:[ESI] pointing to search text
  798.              DS:[EDX] pointing to filespec mask
  799.              EAX = near pointer to FSTRSTR (case-sensetive)
  800.                                 or FSTRISTR (case-insensetive)
  801.  
  802.              GREP searches the file(s) specified at [EDX] for the string
  803.              at [ESI], returning a pointer to a list of filenames in which
  804.              the string was found.  The filename list is in MARKFILE format
  805.              (see MARKFILE in INPUT.DOC)
  806.  
  807. Returns:     if CF = 0, EDI points to MARKFILE-format file list
  808.              if CF = 1, no files match the filespec or the string was not
  809.              found.
  810. Uses:        EDI, EAX, flags
  811. Example:
  812.  
  813. include model.inc
  814.  
  815. public  do_grep
  816. extrn   grep:near
  817. extrn   fstristr:near             ; do case-insensetive search
  818.  
  819. ; look for all .ASM source code that uses FSTRISTR
  820.  
  821. include dataseg.inc
  822. text_string  db 'fstristr',0
  823. filespec     db '*.asm',0
  824. @curseg ends
  825.  
  826. include codeseg.inc
  827.  
  828. do_grep proc near
  829.         lea    edx,filespec       ; point to filespec
  830.         lea    eax,fstristr       ; use case-insensetive routine
  831.         lea    esi,text_string    ; look for 'fstristr'
  832.         call   grep               ; returns filename list at [EDI]
  833.         jc     short oops
  834.  
  835.  
  836. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  837.  
  838. MLOAD:       read a file into near memory
  839. Source:      mload.asm (fsize.asm)
  840.  
  841. Call with:   EDX pointing to ASCIIZ filename
  842. Returns:     if CF = 0, EBX = near pointer to memory block
  843.                         EAX = bytes loaded from disk
  844.              if CF = 1, AX = DOS error code
  845.              CAUTION: prior to ASM32 version 3.4, MLOAD allocated a new
  846.                       selector in FAR memory, returning the selector as BX.
  847.                       MLOAD now allocates NEAR memory.
  848. Uses:        EAX, EBX, CF
  849. Example:
  850.  
  851. include model.inc
  852.  
  853. public  test_mload
  854.  
  855. extrn   mload:near
  856.  
  857. include dataseg.inc
  858. file_ptr        dd ?
  859. fname           db 'filename.txt',0
  860. file_size       dd 0
  861.  
  862. include codeseg.inc
  863.  
  864. test_mload      proc near
  865.         .
  866.         .
  867.  
  868.         lea     edx,fname
  869.         call    mload           ; read file into DOS memory
  870.         jc      short no_good   ;  jump if there was a problem
  871.  
  872.         mov     file_ptr,ebx    ; save pointer to memory block
  873.         mov     file_size,eax   ; save file size
  874.  
  875. no_good:                        ; return with CF = 1 if error
  876.         ret                     ; CF = 0 if no error
  877. test_mload      endp
  878.         end
  879.  
  880.  
  881. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  882.  
  883. MSAVE:       write memory block to file
  884. Source:      msave.asm
  885.  
  886. Call with:   EDX pointing to ASCIIZ filename
  887.              EBX = near address of first byte to write
  888.              EAX = number of bytes to write
  889.              CAUTION: prior to ASM32 version 3.4, MSAVE did not assumed the
  890.                       memory block at EBX was NEAR.  MSAVE now assumes that
  891.                       EBX is a NEAR pointer.
  892. Returns:     if CF = 0, no error
  893.              if CF = 1, AX = DOS error code
  894. Uses:        EAX, flags
  895. Example:
  896.  
  897. include model.inc
  898.  
  899. public  test_msave
  900.  
  901. extrn   msave:near
  902.  
  903. include dataseg.inc
  904. fname           db 'filename.txt',0
  905. file_size       dd 0
  906. file_ptr        dd ?            ; loaded by program
  907.  
  908. include codeseg.inc
  909.  
  910. test_msave      proc near
  911.         .
  912.         .
  913.  
  914.         lea     edx,fname
  915.         mov     eax,file_size
  916.         mov     ebx,file_ptr    ; start at beginning of memory block
  917.         call    msave           ; save as disk file
  918.                                 ; return with CF = 1 if error
  919.         ret                     ; CF = 0 if no error
  920. test_msave      endp
  921.         end
  922.  
  923.  
  924.  
  925. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  926.  
  927. QFNAME:      qualifies a filename
  928. Source:      qfname.asm
  929.  
  930. Call with:   EBX pointing to a filename; the filename may contain
  931.              drive specification and/or complete or partial path name.
  932.              Drive specification and path name not required.
  933. Returns:     ESI pointing to the full DRIVESPEC:\PATH\FILENAME
  934.              ECX = length of full filename
  935.              Note that ESI points to QFName's buffer space; the next
  936.              call to QFName will return a new filename at the same address.
  937. Uses:        ESI, ECX, flags
  938. Example:
  939.  
  940. include dataseg.inc
  941.  
  942. ; data
  943. docs    db '*.doc',0         ; search for .DOC files in current directory
  944.  
  945. @curseg    ends
  946.  
  947. include codeseg.inc
  948.  
  949. ; code
  950.         .
  951.         .
  952.         .
  953.         lea    ebx,docs
  954.         call   qfname        ; returns 'drive:\path\*.doc'
  955.  
  956.  
  957.